﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using System.Text.RegularExpressions;
using EzDesk.DesktopClient.Storage;
using EzDesk.Generic;
using EzDesk.DesktopClient;
using System.IO;

namespace ConsoleTest
{
    [Serializable]
    public class Person
    {
        public int MyProperty { get; set; }
        public string Name { get; set; }
    }
    class Program
    {
        static void Main(string[] args)
        {
            bool a = new bool();
            a.TrueOrFalseDo(() => { }, () => { });
            a.TrueOrFalseDo(() => { return "Ture"; }, () => { return "False"; });

            //Test();

            //Test_DataStorage();


            Console.WriteLine((DateTime.Now - DateTime.Now.AddDays(-0.5)).Days);
            Console.WriteLine((DateTime.Now - DateTime.Now.AddDays(-1)).Days);

            string testUrl = "http://sdfsdfsdf?sdfsdf=aa&target=action";
            var result = Regex.Match(testUrl, @"target=\w+");
            Console.Write(result);

            string test = "fdjka ljfdl stop fjdsla fdj";
            var d = Regex.Match(test, "((?!\bstop\b).)");
            Console.Write(d.Value);
            Console.ReadKey();
            //a.TrueOrFalseDo(Program.Test, Program.Test);
        }

        static void Test()
        {
            List<Person> persons = new List<Person>();
            persons.Add(new Person { MyProperty = 1, Name = "Superwolf" });
            persons.Add(new Person { MyProperty = 2, Name = "Superwolf2" });
            Console.Write(persons.Take(10).Count());

        }
        static void Test_DataStorage()
        {
            List<Person> persons = new List<Person>();
            persons.Add(new Person { MyProperty = 1, Name = "Superwolf" });
            persons.Add(new Person { MyProperty = 2, Name = "Superwolf2" });
            DataStorage ds = new DataStorage();
            string path = ds.GetFilePath("superwolf", "testData");
            if (File.Exists(path))
                File.Delete(path);

            var readOut = ds.Load<List<Person>>("superwolf", "testData");
            if (readOut == null) Console.WriteLine("yes");

            ds.Save(persons, "superwolf", "testData");
            readOut = ds.Load<List<Person>>("superwolf", "testData");

            if (readOut.Count == 2) Console.WriteLine("yes");

            var dic = new Dictionary<string, object>();
            dic["user"] = 1;
            dic["user1"] = "sdkfsajs;";
            dic["user2"] = new Person { MyProperty = 1, Name = "hoho" };
            dic["user3"] = 1;

            ds.Save(dic, "superwolf", "testData");
            var result = ds.Load<Dictionary<string, object>>("superwolf", "testData");
            foreach (var pair in result)
            {
                Console.WriteLine("{0}:{1}", pair.Key, pair.Value);
            }

            Console.ReadKey();
        }
    }
    public static class Extension
    {
        public static bool TrueOrFalseDo(this bool source, Action tureDoMethod, Action falseDoMethod)
        {
            if (source) tureDoMethod();
            else falseDoMethod();
            return source;
        }
        public static bool TrueOrFalseDo(this bool source, Func<object> tureDoMethod, Func<object> falseDoMethod)
        {
            if (source) tureDoMethod();
            else falseDoMethod();
            return source;
        }
    }
}
